<?php
use yii\helpers\ArrayHelper;
use common\library\htmlHelper;
use yii\helpers\Url;

?>
<!--<form class="layui-form" action="/cake-class/edit">-->
<div class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-inline">
            <div class="site-demo-upload">
                <div class="layui-input-inline">
                    <div class="site-demo-upload">
                        <img id="avatar_view"
                             src="<?php if (isset($info['avatar']) && !empty($info['avatar'])) echo HTTP_DOMAIN_ASSETS . '/' . $info['avatar']; ?>">
                        <input id="avatar" type="hidden" name="avatar"
                               value="<?= $info['avatar'] ?>">
                        <div class="site-demo-upbar">
                            <input type="file" name="Assets[image]" id="demo1">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="nickname" value="<?= ArrayHelper::getValue($info, 'nickname') ?>"
                   class="layui-input ">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
            <input type="radio" name="sex" value="1" title="男" <?php if($info['sex']==1){echo 'checked';}?>>
            <input type="radio" name="sex" value="2" title="女" <?php if($info['sex']==2){echo 'checked';}?>>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-inline">
            <input type="text" name="" value="<?= ArrayHelper::getValue($info, 'mobile') ?>"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input type="text" name="password" value=""
                   class="layui-input">（不填写则不修改）
        </div>
    </div>
    <form class="layui-form" action="/member/info">
        <div class="layui-form-item">
            <label class="layui-form-label">当前角色</label>
            <div class="layui-inline">
                <select name="role">
                    <option value="">全部</option>
                    <? foreach ($roleList as $key=>$value):?>
                        <?php
                        $level = '';
                        switch ($value['level']) {
                            case 0:
                                $level =  '├─  ';
                                break;
                            case 1:
                                $level = '│    ├─  ';
                                break;
                            case 2:
                                $level = '│    │    ├─  ';
                                break;
                            case 3:
                                break;
                        }
                        ?>
                        <option value="<?=$value['personnel_class_id']?>"  <?php if( !empty($info) && $info['role']==$value['personnel_class_id']){echo 'selected';}?>  ><?=$level.$value['class_name']?></option>
                    <? endforeach?>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">职位</label>
            <div class="layui-input-inline">
                <input type="text" name="position" value="<?= ArrayHelper::getValue($info, 'position') ?>"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">办公室</label>
            <div class="layui-input-inline">
                <input type="text" name="office" value="<?= ArrayHelper::getValue($info, 'office') ?>"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <input type="radio" name="status" value="1" title="在职" <?php if($info['status']==1){echo 'checked';}?>>
                <input type="radio" name="status" value="0" title="离职" <?php if($info['status']==0){echo 'checked';}?>>
            </div>
        </div>
        <input type="hidden" name="<?= Yii::$app->request->csrfParam ?>" value="<?= Yii::$app->request->csrfToken ?>">
        <input type="hidden" name="member_id" value="<?= ArrayHelper::getValue($info, 'member_id') ?>">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit-btn">操作</button>
            </div>
        </div>

    </form>

</div>
<!--</form>-->
<script>
    layui.use(['layer', 'form', 'upload'], function () {
        var layer = layui.layer,
            form = layui.form();

        form.on('submit(submit-btn)', function (data) {
            var loading = layer.load(0, {shade: <?=Yii::$app->params['layui_shade']?>, time: <?=Yii::$app->params['layui_time']?>});
            $.post(data.form.action, data.field, function (rs) {
                layer.msg(rs.msg);
                if (rs.code === 0) {
                    setTimeout(function () {
                        window.location.href = rs.data.redirect;
                    }, <?=Yii::$app->params['layui_set_timeout']?>);
                }
                layer.close(loading);
            }, 'json');
            return false;
        });
        layui.upload({
            url: '/up/image?token=<?=TOKEN?>&path=user_avatar'
            , elem: '#demo1' //指定原始元素，默认直接查找class="layui-upload-file"
            , ext: 'jpeg|jpg|png'
            , method: 'post' //上传接口的http类型
            , success: function (rs) {
                document.querySelector('#avatar_view').src = rs.data.src;
                document.querySelector('#avatar').value = rs.data.path;
            }
        });
    });
</script>